package feature;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ken
 * Date: 2023-11-26
 * Time: 19:17
 */
public class BrrowOperation implements IOPeration{
    @Override
    public void work(BookList bookList) {
        System.out.println("借阅图书");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你要借阅的图书名字");
        String name = scanner.nextLine();
        int countsize = bookList.getUsedSize();
        for (int i = 0; i < countsize; i++) {
            Book temp = bookList.getBooks(i);
            if(temp.getName().equals(name) &&      //找到并且 没有被借出
                    (!temp.isIsborrow())) {
                temp.setIsborrow(true);
                System.out.println("借阅成功");
                System.out.println(temp);
                return;
            }
            if(temp.getName().equals(name) &&   //找到但是被借出
                    temp.isIsborrow()) {
                //temp.setIsborrow(true);
                System.out.println("你要找的图书已被借出");
                System.out.println(temp);
                return;
            }
        }
        System.out.println("没有找到你要借阅的图书");
    }
}
